#!/usr/bin/env python

from social_class import Social

def init ( l, admin = 0 ):
	s = Social ( l )

	l.layman.add_js ( "modules/social/js/social.js" )
	l.layman.add_css ( "modules/social/gfx/social.css" )

	if s.cfg.get ( 'facebook.lang' ):
		l.layman.add_js ( "modules/social/js/social.facebook.js" )
		l.layman.add_js ( "//connect.facebook.net/%s/all.js" % s.cfg.get ( 'facebook.lang' ), skip_cache = True )

	if s.cfg.get ( 'facebook.app_id' ):
		l.layman.add_js_code ( "social.facebook._appid = '%s';" % s.cfg.get ( 'facebook.app_id' ) )

	l.layman.add_js_code ( "social.init();" )

	if admin and int ( admin ):
		l.layman.add_js ( "modules/social/js/social.admin.js" )
		l.layman.add_css ( "modules/social/gfx/social.admin.css" )
		l.layman.add_js_code ( "social.admin.init();" )

	return ''

def facebook_like ( liwe, url ):
	s = Social ( liwe )
	return s.facebook_format ( 'like', { 'href' : url } )

def facebook_comments ( liwe, url ):
	s = Social ( liwe )
	return s.facebook_format ( 'comments', { 'href' : url } )

def facebook_send ( liwe, **kwargs ):
	return "facebook_send: TODO"

def facebook_login ( liwe ):
	s = Social ( liwe )
	return s.templates [ 'facebook-login' ] % { 'text' : 'Login tramite Facebook' }

